﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeSleeper.Library;
using MbUnit.Framework;

namespace DeSleeper.Tests
{
	[TestFixture]
	public class WakeOnLanNetworkInterfaceFixture
	{
		[Test]
		public void Enable()
		{
			var interfaces = WakeOnLanNetworkInterface.GetAllRelevantInterfaces();
			foreach (var wakeOnLanNetworkInterface in interfaces)
			{
				var wakeOnLanSupported = (wakeOnLanNetworkInterface.WakeOnLanConfiguration.WakeOnLanEnabled !=
				                          ConfigurationState.Unsupported);

				var magicPacketSupported = (wakeOnLanNetworkInterface.WakeOnLanConfiguration.MagicPacketEnabled !=
				                            ConfigurationState.Unsupported);
				
				wakeOnLanNetworkInterface.EnableWakeOnLan();
				if (wakeOnLanSupported)
					Assert.AreEqual(ConfigurationState.Enabled, wakeOnLanNetworkInterface.WakeOnLanConfiguration.WakeOnLanEnabled);

				if (magicPacketSupported)
					Assert.AreEqual(ConfigurationState.Enabled, wakeOnLanNetworkInterface.WakeOnLanConfiguration.MagicPacketEnabled);
			}
		}

		[Test]
		public void Disable()
		{
			var interfaces = WakeOnLanNetworkInterface.GetAllRelevantInterfaces();
			foreach (var wakeOnLanNetworkInterface in interfaces)
			{
				var wakeOnLanSupported = (wakeOnLanNetworkInterface.WakeOnLanConfiguration.WakeOnLanEnabled !=
				                          ConfigurationState.Unsupported);

				var magicPacketSupported = (wakeOnLanNetworkInterface.WakeOnLanConfiguration.MagicPacketEnabled !=
				                            ConfigurationState.Unsupported);

				wakeOnLanNetworkInterface.DisableWakeOnLan();
				if (wakeOnLanSupported)
					Assert.AreEqual(ConfigurationState.Disabled, wakeOnLanNetworkInterface.WakeOnLanConfiguration.WakeOnLanEnabled);

				if (magicPacketSupported)
					Assert.AreEqual(ConfigurationState.Disabled, wakeOnLanNetworkInterface.WakeOnLanConfiguration.MagicPacketEnabled);
			}
		}

		[Test]
		public void Switch()
		{
			var interfaces = WakeOnLanNetworkInterface.GetAllRelevantInterfaces();
			foreach (var wakeOnLanNetworkInterface in interfaces)
			{
				var wakeOnLanSupported = (wakeOnLanNetworkInterface.WakeOnLanConfiguration.WakeOnLanEnabled !=
				                          ConfigurationState.Unsupported);

				var magicPacketSupported = (wakeOnLanNetworkInterface.WakeOnLanConfiguration.MagicPacketEnabled !=
				                            ConfigurationState.Unsupported);

				wakeOnLanNetworkInterface.DisableWakeOnLan();
				if (wakeOnLanSupported)
					Assert.AreEqual(ConfigurationState.Disabled, wakeOnLanNetworkInterface.WakeOnLanConfiguration.WakeOnLanEnabled);

				if (magicPacketSupported)
					Assert.AreEqual(ConfigurationState.Disabled, wakeOnLanNetworkInterface.WakeOnLanConfiguration.MagicPacketEnabled);

				wakeOnLanNetworkInterface.EnableWakeOnLan();
				if (wakeOnLanSupported)
					Assert.AreEqual(ConfigurationState.Enabled, wakeOnLanNetworkInterface.WakeOnLanConfiguration.WakeOnLanEnabled);

				if (magicPacketSupported)
					Assert.AreEqual(ConfigurationState.Enabled, wakeOnLanNetworkInterface.WakeOnLanConfiguration.MagicPacketEnabled);
			}
		}
	}
}